#!/bin/bash

CFG="/etc/nginx/conf.d"
if [ ! -d $CFG ]; then
    mkdir -p "$CFG"
    cp /usr/local/src/default.conf $CFG/default.conf
else
    count=`ls $CFG/*.conf 2> /dev/null|wc -l`
    if [ "$count" != "0" ]; then
       echo "config files: $count"
    else
       echo "config empty!"
       cp /usr/local/src/default.conf $CFG/default.conf
    fi
fi

if [ ! -f "$CFG/handle_cors.lua" ];then
    cp /usr/local/src/handle_cors.lua $CFG/handle_cors.lua
fi

dir="/etc/nginx/conf.d/certs"
if [ ! -d $dir ]; then
    echo "$dir not exists"
    mkdir -p "$dir"
fi

sh -c '/usr/bin/openresty -g "daemon off;"'
